package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.webserver.request.AccountNumberAddRequest;
import com.mingqijia.gassafety.webserver.request.AccountNumberEditRequest;
import com.mingqijia.gassafety.webserver.request.AccountNumberIdRequest;
import com.mingqijia.gassafety.webserver.request.AccountNumberIdsRequest;
import com.mingqijia.gassafety.webserver.request.AccountNumberListRequest;
import com.mingqijia.gassafety.webserver.response.AccountCheckPasswordResp;
import com.mingqijia.gassafety.webserver.response.AccountNumberResp;
import com.mingqijia.gassafety.webserver.response.AccountNumberRoleListResp;
import com.mingqijia.gassafety.webserver.service.AccountNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @program: gassafety
 * @description: 账号管理
 * @author: zm
 * @create: 2024-07-30 10:02
 **/
@Slf4j
@Api(tags = "账号管理")
@RestController(value = "AccountNumberController")
@RequestMapping("/business/v1/account")
public class AccountNumberController {
    @Autowired
    AccountNumberService accountNumberService;


    /**
     * 账号列表
     * @return List
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation("账号列表")
    public CommonResponse<PageUtil<AccountNumberResp>> getList(@RequestBody @Valid AccountNumberListRequest req){
        return accountNumberService.getList(req);
    }

    /**
     * 账号详情
     * @return List
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ApiOperation("账号详情")
    public CommonResponse<AccountNumberResp> detail(@RequestBody @Valid AccountNumberIdRequest req){
        return accountNumberService.detail(req);
    }

    /**
     * 账号新增
     * @return List
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation("账号新增")
    public CommonResponse<Boolean> add(@RequestBody @Valid AccountNumberAddRequest req){
        return accountNumberService.add(req);
    }

    /**
     * 账号编辑
     * @return Boolean
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation("账号编辑")
    public CommonResponse<Boolean> edit(@RequestBody @Valid AccountNumberEditRequest req){
        return accountNumberService.edit(req);
    }

    /**
     * 账号激活
     * @return Boolean
     */
    @RequestMapping(value = "/activate", method = RequestMethod.POST)
    @ApiOperation("账号激活")
    public CommonResponse<Boolean> activate(@RequestBody @Valid AccountNumberIdsRequest req){
        return accountNumberService.activate(req);
    }


    /**
     * 账号锁定
     * @return Boolean
     */
    @RequestMapping(value = "/lock", method = RequestMethod.POST)
    @ApiOperation("账号锁定")
    public CommonResponse<Boolean> lock(@RequestBody @Valid AccountNumberIdsRequest req){
        return accountNumberService.lock(req);
    }

    /**
     * 账号删除
     * @return Boolean
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation("账号删除")
    public CommonResponse<Boolean> delete(@RequestBody @Valid AccountNumberIdsRequest req){
        return accountNumberService.delete(req);
    }

    /**
     * 重置密码
     * @return Boolean
     */
    @RequestMapping(value = "/reset", method = RequestMethod.POST)
    @ApiOperation("账号密码重置")
    public CommonResponse<Boolean> reset(@RequestBody @Valid AccountNumberIdRequest req) {
        if (StringUtils.isEmpty(req.getState())) return CommonResponse.failure("账号状态不能为空");
        return accountNumberService.reset(req);
    }

    /**
     * 重置密码
     * @return Boolean
     */
    @RequestMapping(value = "/role/list", method = RequestMethod.GET)
    @ApiOperation("角色下拉框")
    public CommonResponse< List<AccountNumberRoleListResp>> roleList() {
        return accountNumberService.roleList();
    }


    /**
     * 校验手机号
     * @return Boolean
     */
    @RequestMapping(value = "/check/mobile", method = RequestMethod.GET)
    @ApiOperation("校验手机号")
    public CommonResponse<Boolean> checkMobile(@RequestParam(value = "mobile",required = true) String mobile) {
        return accountNumberService.checkMobile(mobile);
    }


    /**
     * 校验员工工号
     * @return Boolean
     */
    @RequestMapping(value = "/check/staffCode", method = RequestMethod.GET)
    @ApiOperation("校验员工工号")
    public CommonResponse<Boolean> checkStaffCode(@RequestParam(value = "staffCode",required = true) String staffCode) {
        return accountNumberService.checkStaffCode(staffCode);
    }

    /**
     * 校验账号
     * @return Boolean
     */
    @RequestMapping(value = "/check/userCode", method = RequestMethod.GET)
    @ApiOperation("校验账号")
    public CommonResponse<Boolean> checkUserCode(@RequestParam(value = "userCode",required = true) String userCode) {
        return accountNumberService.checkUserCode(userCode);
    }

    /**
     * 校验密码是否符合规则
     * @return Boolean
     */
    @RequestMapping(value = "/check/password", method = RequestMethod.GET)
    @ApiOperation("校验密码是否符合规则")
    public CommonResponse<AccountCheckPasswordResp> checkPassword(@RequestParam(value = "password",required = true) String password) {
        return accountNumberService.checkPassword(password);
    }

    /**
     * 根据规则生成密码
     * @return Boolean
     */
    @RequestMapping(value = "/genPassword", method = RequestMethod.GET)
    @ApiOperation("根据规则生成密码")
    public CommonResponse<Object> genPassword() {
        return accountNumberService.genPassword();
    }

    /**
     * 查询密码规则 若没有，取集团
     * @return Boolean
     */
    @RequestMapping(value = "/queryPwdConfig", method = RequestMethod.GET)
    @ApiOperation("查询密码规则 若没有，取集团")
    public CommonResponse<Object> queryPwdConfig() {
        return accountNumberService.queryPwdConfig();
    }
}
